package com.jk.controller;

import com.alibaba.fastjson.JSON;
import com.jk.service.UserService;
import com.jk.utils.IdCardUtils;
import com.jk.utils.ReturnMsgUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.text.DateFormat;
import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName IdNumberVerificationController
 * @Descripttion TODO  身份账号验证
 * @Author DELL
 * @Date 2022/11/9 16:14
 * @Version 0.001
 */
@RestController
public class IdNumberVerificationController {

    @Autowired
    private UserService userService;

    /**
     * @Author: binzi
     * @Description: 身份账号验证接口
     * @Date: 2022/11/9 16:11
     * @Return: void
     **/
    @RequestMapping("IdNumberVerification")
    public Map IdNumberVerification(String[] args,String name,String idcard) throws IOException {
        String url = "https://eid.shumaidata.com/eid/check";
        String appCode = "d3260fa621eb4e07a252f1eb3a6cbf47";

        Map<String, String> params = new HashMap<>();
//        410381200101299679 牛毅斌
        params.put("idcard", idcard);
        params.put("name", name);
        String result = IdCardUtils.postForm(appCode, url, params);
        Map map = JSON.parseObject(result, HashMap.class);

        Map result1 = (Map) map.get("result");

        if (map.get("code").equals("0")){
            if (result1.get("description").equals("一致")){
                System.out.println(map.get("code"));
                System.out.println(map.get("result"));
                System.out.println(result1.get("description"));
                System.out.println(map);
                //实名认证
                userService.updateUserByPhoneAndIdCard(name,idcard);
                return ReturnMsgUtils.returnMsg(200,"实名认证成功！！！",true);
            }else {
                return ReturnMsgUtils.returnMsg(500,"姓名无效！！！",false);
            }
        }else {
            return ReturnMsgUtils.returnMsg(500,"身份证号无效！！！",false);
        }




    }
}
